<template>
  <div class="home">
    <div class="header">
      <span>我的收藏</span>
    </div>

    <div class="content">
      <div class="context">
        <div class="header_a">
          <el-tag class="h_a"><i class="el-icon-document"></i>收藏</el-tag>
          <span class="h_b"
            ><i class="el-icon-edit-outline"></i>收藏数量:{{ totle }}</span
          >
        </div>
        <el-tabs
          type="border-card"
          v-model="activeName"
          @tab-click="handleClick"
        >
          <el-tab-pane name="all">
            <span slot="label"><i class="el-icon-menu"></i> 全部</span>
            <div class="c_item" v-for="item in listDate">
              <div class="c_it_content">
                <div class="avatars">
                  <div class="av_h">
                    <i class="el-icon-paperclip"></i>
                  </div>
                </div>
                <div class="avatars">
                  <div class="span">
                    <span @click="btnhead(item.inviteCode)">{{
                      item.inviteTitle
                    }}</span>
                  </div>
                  <div class="b">
                    <span> <el-tag size="small">公告</el-tag></span>
                    <span>创建时间：{{ item.bytime }}</span>
                  </div>
                </div>
              </div>
              <div class="c_item_right">
                <el-button
                  size="mini"
                  type="danger"
                  icon="el-icon-delete"
                  circle
                  @click="deleteSC(item)"
                ></el-button>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import { getListDateByUserCode, deleteShoucang } from "../api/cate";
// import sc from "@/api/cate";
export default {
  name: "mySC",
  data() {
    return {
      url: "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2789251979,2162125395&fm=26&gp=0.jpg",
      listDate: [],
      activeName: "all",
      totle: "",
    };
  },
  activated: function () {
    this.getData();
  },
  methods: {
    getData() {
      this.loading.startLoading();
      let obj1 = {
        userCode: sessionStorage.getItem("userCode"),
      };
      //模块1
      getListDateByUserCode(obj1).then((res) => {
        if (res.data.code === 200) {
          this.listDate = res.data.data.ListData;
          this.totle = this.listDate.length;
        } else {
          this.$message.error("没有数据");
          //  res.data.data.list
        }
      });
      this.loading.endLoading();
    },
    btnhead(val) {
      console.log(val);
      // this.$router.go(0)
      this.$router.replace({
        path: "/show",
        query: {
          inviteCode: val,
        },
      });
    },
    handleClick(tab, event) {
      console.log(tab.name);
    },
    deleteSC(val) {
      this.$confirm("取消收藏, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          if (this.listDate.length > 1) {
            let obj1 = {
              inviteCode: val.inviteCode,
              userCode: sessionStorage.getItem("userCode"),
            };
            deleteShoucang(obj1)
              .then((res) => {
                if (res.data.code === 200) {
                  this.$message({
                    type: "success",
                    message: "取消收藏成功!",
                  });
                  this.getData();
                }
              })
              .catch((error) => {
                this.$message({
                  type: "error",
                  message: "取消收藏失败!",
                });
              });
          } else {
            this.$message({
              type: "error",
              message: "最后一条数据无法取消!",
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
<style scoped>
.home {
  background-image: url(../assets/images/banner.png);
  background: #fff;
  width: 100%;
  height: 700px;
  text-align: center;
  margin: 0 auto;
  overflow: auto;
}
.content {
  padding-top: 50px;
  width: 80%;
  margin: 0 auto;
}
.header {
  width: 100%;
  height: 200px;
  line-height: 200px;
  text-align: center;
  font-size: 72px;
  color: #fff;
  font-family: "STKaiti";
  background-image: url(../assets/images/banner.png);
  /* background: rgb(134, 179, 10); */
}
.zhongjian {
  width: 100%;
  height: 400px;
  /* background: #ccc; */
}
.header_a {
  width: 100%;
  height: 40px;
  line-height: 40px;
}
.h_a {
  float: left;
  margin-right: 10px;
  color: rgb(38, 177, 241);
  cursor: pointer;
}
.h_b {
  float: right;
  margin-right: 10px;
  font-size: 12px;
  color: rgb(38, 177, 241);
}
.c_item {
  width: 100%;
  height: 70px;
  float: left;
  margin: 0 auto;
  border-bottom: 1px solid #ccc;
}
.c_it_content {
  width: 50%;
  float: left;
}
.avatars {
  margin-right: 15px;
  height: 60px;
  line-height: 30px;
  float: left;
}
.avatars .av_h {
  padding-top: 10px;
}
.avatars .span {
  height: 50%;
  padding-left: 5px;
  width: 280px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.avatars .b {
  height: 50%;
  color: rgb(250, 224, 191);
  padding-left: 5px;
  width: 280px;
  text-align: left;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.c_item_right {
  height: 70px;
  line-height: 70px;
  float: right;
}
.el-carousel__item h3 {
  color: #f8f9fa;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #f6f8fa;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #f7f8fa;
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
</style>

<style>
</style>